﻿Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Runtime.Serialization
Imports System.Text
Imports Common

Public Class Players
    Private Shared _PlayerCollection As New List(Of playerDTO)
    Private Shared _PlayersSyncLock As New Object

    Public Shared ReadOnly Property [Get] As List(Of playerDTO)
        Get
            SyncLock _PlayersSyncLock
                Return _PlayerCollection
            End SyncLock
        End Get
    End Property

    Public Shared Sub Add(playerToAdd As playerDTO)
        SyncLock _PlayersSyncLock
            For Each Player As playerDTO In _PlayerCollection
                If Player.ID = playerToAdd.ID Then 'If player already added/exists then replace them.
                    Player = playerToAdd
                    Exit Sub
                End If
            Next
            _PlayerCollection.Add(playerToAdd)
        End SyncLock
    End Sub

    Public Shared Function getPlayerByGUID(guid As String) As playerDTO
        For Each p As playerDTO In Players.[Get]
            If p.GUID.ToString = guid Then Return p
        Next
        Return New playerDTO
    End Function
End Class
